﻿using System;
using System.Collections.Generic;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Defines an HTML5 audio element.
    /// </summary>
    [Serializable]
    public class Audio : Element {
        private bool _autoplay;
        private bool _controls;
        private bool _loop;
        private bool _muted;
        private PreloadChoices? _preload;
        private string _src;

        /// <summary>
        /// Constructs a new Audio element.
        /// </summary>
        public Audio() {}

        /// <summary>
        /// Constructs a new Audio element with the given source URL.
        /// </summary>
        /// <param name="src"></param>
        public Audio(string src) {
            _src = src;
        }

        /// <summary>
        /// Determines whether or not the audio should automatically play back.
        /// </summary>
        public bool AutoPlay {
            get { return _autoplay; }
            set { _autoplay = value; }
        }

        /// <summary>
        /// Determines whether or not controls should be shown.
        /// </summary>
        public bool Controls {
            get { return _controls; }
            set { _controls = value; }
        }

        /// <summary>
        /// Determines whether or not the audio should be played in a loop.
        /// </summary>
        public bool Loop {
            get { return _loop; }
            set { _loop = value; }
        }

        /// <summary>
        /// Determines whether or not the audio is muted by default.
        /// </summary>
        public bool Muted {
            get { return _muted; }
            set { _muted = value; }
        }

        /// <summary>
        /// Determines what parts of the audio to preload automatically.
        /// </summary>
        public PreloadChoices? Preload {
            get { return _preload; }
            set { _preload = value; }
        }

        /// <summary>
        /// Determines the source file for the audio.
        /// </summary>
        public string Src {
            get { return _src; }
            set { _src = value; }
        }

        /// <summary>
        /// Writes out the local attributes of this audio tag.
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _autoplay, "autoplay");
            AttributeWriter.Write(sb, _controls, "controls");
            AttributeWriter.Write(sb, _loop, "loop");
            AttributeWriter.Write(sb, _muted, "muted");
            AttributeWriter.Write(sb, _preload, "preload", true);
            AttributeWriter.Write(sb, _src, "src");
        }
    }
}
